/*
 * Copyright (c) 2020-2099 the original author or authors. All rights reserve.
 */
package org.tianyun.cloud.amqp.rabbitmq.advice;

import org.springframework.amqp.core.Message;

import java.lang.reflect.Method;

/**
 * Message消息拦截器
 *
 * @auther ebert_chan
 */
public interface MessageAdvice extends ListenerInvokeAdvice {

    void onBefore(Message message) throws Throwable;

    /*
     * @see org.tianyun.cloud.amqp.rabbitmq.advice.ListenerInvokeAdvice#onBefore(java.lang.reflect.Method, java.lang.Object[])
     */
    @Override
    default void onBefore(Method method, Object[] args) throws Throwable {
        if (args == null || args.length == 0) {
            return;
        }
        Message message = null;
        for (Object parameter : args) {
            if (parameter instanceof Message) {
                message = (Message) parameter;
                break;
            }
        }
        if (message != null) {
            this.onBefore(message);
        }
    }

}
